package views
{
	import inerface.IShopDetailPanel;
	import inerface.IViewSpotDetailPanel;
	
	import main.ClientConstants;
	import main.ViewSubBase;
	
	import panel.shopDetail.ShopDetailPanel;
	import panel.viewSpots.ViewSpotDetailNew;
	
	import struct.Restaurant;
	import struct.UserComment;
	
	public class ShopDetailView extends ViewSubBase
	{
		private var _panel:IViewSpotDetailPanel;
		private var currentShopId:int = 0;
		
		public function ShopDetailView()
		{
		}
		
		public function set shopId(id:int):void
		{
			currentShopId = id;
		}
		
		public override function show():void
		{
			render();
		}
		
		protected override function render():void
		{
			if(_panel == null){
				_panel = new ViewSpotDetailNew();
				_panel.init(view.layout.stage,view.resourceLoader,view.lang,view.uri);
//				_panel.openPhotoRead = view.photoRead.show;
//				_panel.onOpenNavigation = view.navigation.show;
				_panel.openTextPanel = view.textPanel.showDataPanel;
				_panel.openCommentPanel = view.commentList.show;
				
				var shopObj:Restaurant;
				for(var i:int = 0;i < data.viewSpot.resturantList.length;i++){
					if(data.viewSpot.resturantList[i]["id"] == currentShopId){
						shopObj = data.viewSpot.resturantList[i];
						break;
					}
				}
				
				_panel.show(shopObj,this.data.viewSpot.viewSpotsData.spotList);
			}
			this.addView(_panel);
		}
		
		private function addToPath(obj:*):void
		{
			var bool:Boolean = data.choosePath.element(obj);
			if(bool == true){
				view.alert.showAlert("<b>" + "添加成功" + "</b>","确定");
				return;
			}else{
				view.alert.showAlert("<b>" + "当前编辑路线中已添加该地点" + "</b>","返回");
				return;
			}
		}
		
		public override function close():void
		{
			view.layout.closeView(this);
		}
		
		public override function clear():void
		{
			if(_panel){
				_panel.clear();
				_panel = null;
			}
		}
		
		private function commentThis():void
		{
			view.comment.shopType = ClientConstants.COMMENT_TYPE_RESTURANT;
			view.comment.info = currentShopId;
			view.comment.show();
		}
		
		private function showLocation(obj:*):void
		{
			view.showLocation.objInfo = obj;
			view.showLocation.show();
		}
	}
}